<%@ Page Language="C#" MasterPageFile="~/cms.master" AutoEventWireup="true" CodeFile="ProductsList.aspx.cs"
    Inherits="ProductList" Title="<%$Resources:Language,CmsProductsListTitle %>" %>

<%@ Register Src="../controls/ctrlShowInfo.ascx" TagName="ctrlShowInfo" TagPrefix="uc1" %>
<%@ Register Assembly="Winthusiasm.HtmlEditor" Namespace="Winthusiasm.HtmlEditor"
    TagPrefix="cc2" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ac" %>
<%@ Register Src="~/controls/ctrlCategoryTreeView.ascx" TagName="CategoryTreeView"
    TagPrefix="uc" %>
<%@ Register Src="~/controls/ctrlWait.ascx" TagName="ctrlWait" TagPrefix="uc" %>
<%@ Register Src="~/controls/ctrlSearchProduct.ascx" TagName="ctrlSearchProduct"
    TagPrefix="uc" %>
<%@ Register Src="../controls/ctrlShowInfo.ascx" TagName="ctrlShowInfo" TagPrefix="uc" %>
<%@ Register Src="~/controls/ctrlPager.ascx" TagName="ctrlPager" TagPrefix="uc" %>
<%@ Register Src="~/controls/ctrlProductChoose.ascx" TagName="ctrlProductChoose"
    TagPrefix="ctrl" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphMain" runat="Server">
    <h2>
        <%=Resources.Language.Products %></h2>
    <uc:ctrlWait ID="ctrlWait" runat="server" />
    <ac:TabContainer runat="server" ID="tbcProducts" ActiveTabIndex="0">
        <ac:TabPanel ID="tabProducts" runat="server" HeaderText="<%$ Resources:Language,Products %>">
            <ContentTemplate>
                <asp:UpdatePanel ID="pnlProducts" runat="server">
                    <ContentTemplate>
                        <div id="productsList">
                            <uc:ctrlShowInfo ID="csiProductList" runat="server" />
                            <div class="vSeparate">
                                <uc:ctrlSearchProduct ID="ctrlSearchProduct" runat="server" OnProductSearch="ctrlSearchProduct_ProductSearch"
                                    OnClearSearchCriteria="ctrlSearchProduct_ClearSearchCriteria" />
                            </div>
                            <table class="cctTable vSeparate">
                                <tr>
                                    <td>
                                        <ac:CollapsiblePanelExtender ID="cpCategory" runat="server" TargetControlID="pnlCategoryTree"
                                            ExpandControlID="pnlCategoryName" CollapseControlID="pnlCategoryName" Collapsed="true"
                                            ImageControlID="imColapseImg" ExpandedImage="../gfx/expand_smal.gif" CollapsedImage="../gfx/collapse_smal.gif">
                                        </ac:CollapsiblePanelExtender>
                                        <div class="cctHeader">
                                            <span class="cctTrigger">
                                                <asp:Panel ID="pnlCategoryName" runat="server">
                                                    <asp:Image ID="imColapseImg" runat="server" ImageUrl="../gfx/collapse_smal.gif" />
                                                    <%=Resources.Language.Category %>:
                                                    <asp:Label ID="lblChoosenCategoryName" runat="server" Text="<%$ Resources:Language,AllCategories %>"></asp:Label>
                                                    <asp:Label ID="lblFilter" runat="server" Text=""></asp:Label>
                                                </asp:Panel>
                                            </span><span class="cctControl">
                                                <%=Resources.Language.ProductsPerPage %>:
                                                <asp:DropDownList Height="20px" ID="ddlProductsPerPage" runat="server" AutoPostBack="True"
                                                    OnSelectedIndexChanged="ddlProductsPerPage_SelectedIndexChanged">
                                                    <asp:ListItem Value="10">10</asp:ListItem>
                                                    <asp:ListItem Value="25">25</asp:ListItem>
                                                    <asp:ListItem Value="50" Selected="True">50</asp:ListItem>
                                                    <asp:ListItem Value="100">100</asp:ListItem>
                                                    <asp:ListItem Value="200">200</asp:ListItem>
                                                </asp:DropDownList>
                                            </span>
                                        </div>
                                        <asp:Panel ID="pnlCategoryTree" runat="server">
                                            <div class="cctContent">
                                                <uc:CategoryTreeView ID="tvCategory" runat="server" OnSelectedNodeChange="CategoryTreeView_SelectedNodeChanged"
                                                    NodeSelectAction="Select" RootSelectAction="Select" />
                                            </div>
                                        </asp:Panel>
                                    </td>
                                </tr>
                            </table>
                            <asp:GridView ID="gvProductsPreview" runat="server" AutoGenerateColumns="False" CssClass="cmsTables">
                                <Columns>
                                    <asp:TemplateField HeaderText="Id" SortExpression="StorageListId">
                                        <ItemTemplate>
                                            <%# ((ShopModel.Products)Container.DataItem).IDproduct.ToString() %>
                                        </ItemTemplate>
                                        <ItemStyle HorizontalAlign="Center" Width="20px" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="<%$ Resources:Language,Name %>" SortExpression="ProductName">
                                        <ItemTemplate>
                                            <a href='ProductEdit.aspx?EditProduct=<%# Eval("IDproduct") %>' style='<%# LeafCategories.Contains(Convert.ToInt32(Eval("CategoryID"))) ? "": "color:red" %>'>
                                                <%# ((ShopModel.Products)Container.DataItem).Name%>
                                            </a>
                                        </ItemTemplate>
                                        <HeaderStyle HorizontalAlign="Center" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="<%$ Resources:Language,PriceBrutto %>" SortExpression="CategoryName">
                                        <ItemTemplate>
                                            <%# ((ShopModel.Products)Container.DataItem).PriceBrutto.ToString()%>
                                        </ItemTemplate>
                                        <HeaderStyle HorizontalAlign="Center" />
                                        <ItemStyle HorizontalAlign="Center" />
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="AvailableCount" HeaderText="<%$ Resources:Language,ItemsInStorage %>" />
                                </Columns>
                            </asp:GridView>
                            <uc:ctrlPager ID="ctrlPager" runat="server" OnPageIndexChanged="ctrlPager_PageIndexChanged" />
                        </div>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </ContentTemplate>
        </ac:TabPanel>
        <ac:TabPanel ID="tabXML" runat="server" HeaderText="<%$ Resources:Language,ExportImport %>">
            <ContentTemplate>
                <asp:UpdatePanel ID="upImportProducts" runat="server">
                    <ContentTemplate>
                        <div id="importExport">
                            <uc1:ctrlShowInfo ID="csiImportExport" runat="server" />
                            <div class="vSeparate">
                                <span class="peBoxLeft">
                                    <%=Resources.Language.ExportProductsToFile %>: </span><span class="peBoxRight">
                                        <asp:TextBox runat="server" ID="tbName" Width="200px" /><asp:RequiredFieldValidator
                                            ID="rfvName" Display="Dynamic" ControlToValidate="tbName" ErrorMessage="*" ValidationGroup="GenerateXml"
                                            runat="server"></asp:RequiredFieldValidator>
                                        <asp:Button runat="server" ID="btnSaveXml" Text="<%$ Resources:Language,GenerateFileXml %>"
                                            OnClick="btnWriteXml_Click" ValidationGroup="GenerateXml" />
                                    </span>
                            </div>
                            <div class="vSeparate">
                                <span class="peBoxLeft">
                                    <%= Resources.Language.ImportXmlFile %>:</span><span class="peBoxRight">
                                        <asp:FileUpload ID="fuFile" runat="server" />
                                        <asp:Button ID="btnAddFile" runat="server" Text="<%$ Resources:Language, Import %>" OnClick="btnAddFile_Click" />
                                    </span>
                            </div>
                            <div class="vSeparate">
                                <span class="peBoxLeft">
                                    <%= Resources.Language.ExportedFilesOnServer %>:</span><span class="peBoxRight">
                                        <asp:GridView ID="gvFile" runat="server" AutoGenerateColumns="False" CssClass="cmsTables">
                                            <Columns>
                                                <asp:TemplateField HeaderText="<%$ Resources:Language,FileName %>">
                                                    <ItemTemplate>
                                                        <%# ((System.IO.FileInfo)Container.DataItem).Name.ToString()%>
                                                    </ItemTemplate>
                                                    <ItemStyle Width="35%" />
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="<%$ Resources:Language,CreationDate %>">
                                                    <ItemTemplate>
                                                        <%# ((System.IO.FileInfo)Container.DataItem).CreationTime.ToString()%>
                                                    </ItemTemplate>
                                                    <ItemStyle Width="20%" />
                                                </asp:TemplateField>
                                                <asp:TemplateField>
                                                    <ItemTemplate>
                                                        <!--<a href="<%# ShopModel.Settings.XmlBackupDirectory.Replace("~","..") + "/" + ((System.IO.FileInfo)Container.DataItem).Name.ToString()%>">
                                                            <%=Resources.Language.Download%></a>-->
                                                        <asp:LinkButton ID="lbnDownload" runat="server" OnCommand="lbnCommand" CommandName="download"
                                                            CommandArgument="<%# ((System.IO.FileInfo)Container.DataItem).Name.ToString()%>"
                                                            Text="<%$ Resources:Language,Download%>">                                            
                                                        </asp:LinkButton>                                                            
                                                    </ItemTemplate>
                                                    <ItemStyle Width="15%" />
                                                </asp:TemplateField>
                                                <asp:TemplateField>
                                                    <ItemTemplate>
                                                        <asp:LinkButton ID="lbnLoad" runat="server" OnCommand="lbnCommand" CommandName="load"
                                                            CommandArgument="<%# ((System.IO.FileInfo)Container.DataItem).Name.ToString()%>"
                                                            Text="<%$ Resources:Language,LoadData%>">                                            
                                                        </asp:LinkButton>
                                                    </ItemTemplate>
                                                    <ItemStyle Width="15%" />
                                                </asp:TemplateField>
                                                <asp:TemplateField>
                                                    <ItemTemplate>
                                                        <asp:LinkButton ID="lbnDelete" runat="server" OnCommand="lbnCommand" CommandName="delete"
                                                            CommandArgument="<%# ((System.IO.FileInfo)Container.DataItem).Name.ToString()%>"
                                                            Text="<%$ Resources:Language,Remove %>">                                            
                                                        </asp:LinkButton>
                                                    </ItemTemplate>
                                                    <ItemStyle Width="15%" />
                                                </asp:TemplateField>
                                            </Columns>
                                        </asp:GridView>
                                    </span>
                            </div>
                            <% if (gvProducts.Rows.Count > 0)
                               {%>
                            <div class="vSeparate">
                                <span class="peBoxLeft"></span><span class="peBoxRight">
                                    <asp:Button ID="btnImportProductsTop" runat="server" Text="<%$ Resources:Language,ImportProducts %>"
                                        OnClick="btnImportProducts_Click" Enabled="false" />
                                </span>
                            </div>
                            <div class="vSeparate">
                                <span class="peBoxLeft"></span><span class="peBoxRight">
                                    <asp:GridView ID="gvProducts" runat="server" AutoGenerateColumns="False" CssClass="cmsTables">
                                        <Columns>
                                            <asp:TemplateField>
                                                <ItemTemplate>
                                                    <asp:CheckBox ID="cbProduct" runat="server" AutoPostBack="false" onclick="Select(this)" />
                                                </ItemTemplate>
                                                <HeaderTemplate>
                                                    <asp:CheckBox ID="cbSelectAll" runat="server" AutoPostBack="false" onclick="SetAll(this)" />
                                                </HeaderTemplate>
                                                <ItemStyle HorizontalAlign="Right" Width="20px" />
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="<%$ Resources:Language,Name %>" SortExpression="ProductName">
                                                <ItemTemplate>
                                                    <%# ((ShopModel.Products)Container.DataItem).Name.ToString() %>
                                                </ItemTemplate>
                                                <ItemStyle HorizontalAlign="Left" />
                                            </asp:TemplateField>
                                        </Columns>
                                    </asp:GridView>
                                </span>
                            </div>
                            <div class="vSeparate">
                                <span class="peBoxLeft"></span><span class="peBoxRight">
                                    <asp:Button ID="btnImportProductsBottom" runat="server" Text="<%$ Resources:Language,ImportProducts %>"
                                        OnClick="btnImportProducts_Click" OnClientClick="ScrollTop();" Enabled="false" />
                                </span>
                            </div>
                            <%} %>
                        </div>
                    </ContentTemplate>
                    <Triggers>
                        <asp:PostBackTrigger ControlID="btnAddFile" />
                    </Triggers>
                </asp:UpdatePanel>
            </ContentTemplate>
        </ac:TabPanel>
    </ac:TabContainer>

    <script language="javascript" type="text/javascript" src="../Javascript/ProductsList.js"></script>

    <script language="javascript" type="text/javascript" src="../Javascript/Common.js"></script>

</asp:Content>
